{include file = $smarty.const.APPLICATION_PATH|cat:"/application/views/header.html"}

<section class="wrap">
    <!--content stop-->

    <section class="login">
        <ul>
            <form method="post" target="_self" id="myForm" name="myForm"  action="/findpasswd/steptow">
                <input class="login-text" type="hidden"  name="codetime"/>
                <li><input class="login-text" type="text"  name="mobile" placeholder="请输入手机号码"/>
                    <span class="phonemsg"></span>
                </li>
                <li class="verification_code">
                    <input class="login-code" type="text" value="" name="code" placeholder="请输入验证码"/>
                    <div class="code-pic"><img src="/login/code"  id="login_code_img" onclick="change_code()" width="100%" height="40"  /></div>
                    <span class="msg"></span>
                </li>
                <li><input class="login-btn" type="button"  value="下一步"/></li>
            </form>
        </ul>
    </section>

    <!--content end-->

    {include file = $smarty.const.APPLICATION_PATH|cat:"/application/views/common/footerlogin.html"}

</section>
{literal}
<script type="text/javascript">

    function change_code(){
        var img = document.getElementById('login_code_img');
        img.src = '/login/code/rand/' + Math.random();
    };


    $(function(){
        var Obmobile = $("input[name=mobile]");
        var Obcode = $("input[name=code]");

        $('.login-btn').click(function(){
            if(validatemobile(Obmobile)==false || ncodeEmpty(Obcode) ==false){
                alert("2");
                return false;
            }else{

                document.myForm.submit();
            }
        });

        Obmobile.blur(function(){
            validatemobile(Obmobile);
        });

        Obcode.blur(function(){
            ncodeEmpty(Obcode);
        });

    });


    $(function(){
        $('.smxy').click(function(){
            $('.popup_smxy_bg').show();
            $('.popup_smxy').show();
        });

        $('.close_smxy').click(function(){
            $('.popup_smxy_bg').hide();
            $('.popup_smxy').hide();
        });
    });


    function validatemobile(mobile)
    {
        var mobile = mobile.val();
        var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;

        if(mobile.length==0)
        {
            $(".phonemsg").html("请输入手机号码！");
            return false;
        }else if(mobile.length!=11)
        {
            $(".phonemsg").html("请输入有效的手机号码！");
            return false;
        }else if(!myreg.test(mobile))
        {
            $(".phonemsg").html("请输入有效的手机号码！");
            return false;
        }else if(isExistMobile(mobile)  ==false) {
            $(".phonemsg").html("该手机号不存在！");
            return false;
        }else{
            $(".phonemsg").html("");
            return true;
        }
    }

    function isExistMobile(mobile){
        $.ajax({
            url:'/register/isExistMobile',
            data:{mobile:mobile},
            async:false,
            type:'POST',
            success:function(data){
                var data = eval("("+data+")");
                var code = data.code;
                var msg = data.msg;
                if(code == 38){
                    result =  false;
                }else{
                    $(".phonemsg").html("");
                    result= true;
                }
            },
            dataType:'text'
        });

        return result;
    }

    function ncodeEmpty(obj){
        Value = obj.val();
        var mobile = $("input[name=mobile]").val();
        if(Value==''){
            $('.msg').html("请输入验证码！");
            return false;
        }else{
            var code = Value;
            $.ajax({
                url:'/register/confirmcode',
                data:{code:code,mobile:mobile},
                async:false,
                type:'POST',
                success:function(data){
                    var data = eval("("+data+")");
                    var code = data.code;
                    var msg = data.msg;
                    var data = data.data;
                    if(code == 8){
                        $(".msg").html("");
                        $("input[name=codetime]").val(data.vcode);
                        result =  true;
                    }else{
                        $(".msg").html(msg);
                        change_code();
                        result= false;
                    }
                },
                dataType:'text'
            });
            return result;
        }
    }


</script>
{/literal}

{include file = $smarty.const.APPLICATION_PATH|cat:"/application/views/footer.html"}

